package com.cg.service.impl;

import java.util.Collection;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cg.dao.MapBuildingDao;
import com.cg.entity.MapBuilding;
import com.cg.entity.MapGrid;
import com.cg.utils.FilterRule;
import com.cg.utils.FilterRuleBuilder;
import com.cg.utils.R;

@Service
public class MapBuildingService {

	@Autowired
	private MapBuildingDao mapBuildingDao;
	
	public List<MapBuilding> getAll(){
		return mapBuildingDao.findAll();
	}
	
	public MapBuilding getById(Integer id) {
		List<FilterRule> filterRules = FilterRuleBuilder.newBuilder().key("id").eq().value(id)
                .build();
		List<MapBuilding> buildings= mapBuildingDao.findByCondition(filterRules);
		if(null != buildings) {
			return buildings.get(0);
		}
		return null;
	}
	
	
	public List<MapBuilding> getByIds(Collection<Integer> ids) {
		List<FilterRule> filterRules = FilterRuleBuilder.newBuilder().key("id").in().value(ids)
                .build();
		return mapBuildingDao.findByCondition(filterRules);
	}

//	public PageAjax<MapBuilding> queryBuildingPage(PageAjax<AppMenu> page, MapBuilding mapBuilding) {
//		PageMethod.startPage(page.getPageNo(), page.getPageSize());
//		return AppUtil.returnPage(getAll());
//	}
	public List<MapBuilding> queryList(Map<String, Object> params){
		
		return mapBuildingDao.queryList(params);
	}
	
	public R save(MapBuilding mapbuilding){
		mapBuildingDao.save(mapbuilding);
		return R.ok();
	}
	
	public int queryTotal(Map<String,Object> query) {
		
		return mapBuildingDao.queryTotal();
	}
	
	public R update(MapBuilding mapbuilding){
		mapBuildingDao.update(mapbuilding);
		return R.ok();
	}
	
	public void deleteBatch(Long[] ids) {
		mapBuildingDao.deleteBatch(ids);
	}

	public MapBuilding queryObject(Long id) {
		return mapBuildingDao.queryObject(id);
	}
}
